<template>
  <!-- 商品详情-关联直播8/135 -->
  <div id="liveDetails">
    <template v-if="vipRootObj[8][135].owner">
      <template v-if="!once">
        <div class="top">
          <radio_group01 :radio_values="['近7天', '30天', '90天']" v-model="KindName" class="tab01" />
          <div class="optionsBox">
            <el-date-picker
              class="long_time"
              v-model="liveTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              prefix-icon="el-icon-arrow-down"
              unlink-panels
              :clearable="false"
              :picker-options="pickeroptions"
              value-format="yyyy-MM-dd"
              @change="onPick1"
            ></el-date-picker>
          </div>
        </div>
        <!-- 直播销量趋势 -->
        <div class="livetrend">
          <div class="title">直播销量趋势</div>
          <div class="volume">
            <div>
              总销量(件)
              <span>{{format_num(trend.volume)}}</span>
            </div>
            <div>
              总销售额
              <span>{{format_num(trend.amount)}}</span>
            </div>
          </div>
          <div class="trend">
            <KChart
              v-if="!plLoading && trendX.length "
              :xData="trendX"
              :series1="trendY"
              name1="销量"
            />
            <div class="no_data" v-if="!trendX.length && !plLoading">
              <img src="@/assets/shi/zanwushuju.png" alt />
              暂无数据
            </div>
            <div
              v-loading="plLoading"
              v-if="plLoading"
              class="loading"
              element-loading-spinner="el-icon-loading"
            ></div>
          </div>
        </div>
        <!-- 直播列表 -->
        <div class="title">直播列表</div>
        <div class="searchBox">
          <el-input
            type="text"
            v-model="keyWords"
            @keyup.enter.native="Search"
            placeholder="请输入达人名称或直播间名称搜索"
          ></el-input>
          <div class="imgBox" @click="Search">
            <!-- <img src="@/assets/wang/talentCompare/search.png" /> -->
          </div>
        </div>

        <table class="table">
          <thead>
            <tr>
              <th>直播间</th>
              <th>达人</th>
              <!-- <th @click="sort_fun(false, 4)" v-if="orderBy == 'asc' && sort ==4">
            讲解时长
            <img src="@/assets/meng/up_down.png" v-if="orderBy =='asc' && sort == 4" /><img
              src="@/assets/meng/no_down_up.png" v-else />
          </th>
          <th v-else @click="sort_fun(true, 4)">
            讲解时长
            <img src="@/assets/meng/down_up.png" v-if="orderBy == 'desc' && sort == 4" class="sort" /><img
              src="@/assets/meng/no_down_up.png" v-else />
              </th>-->

              <th @click="sort_fun(false, 1)" v-if="orderBy == 'desc' && sort == 1" class="cursor">
                直播价格
                <img
                  src="@/assets/meng/down_up.png"
                  v-if="orderBy == 'desc' && sort == 1"
                  class="sort"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>
              <th v-else @click="sort_fun(true, 1)">
                直播价格
                <img src="@/assets/meng/up_down.png" v-if="orderBy == 'asc' && sort == 1" />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>

              <th @click="sort_fun(false, 2)" v-if="orderBy == 'desc' && sort == 2" class="cursor">
                直播销量
                <img
                  src="@/assets/meng/down_up.png"
                  v-if="orderBy == 'desc' && sort == 2"
                  class="sort"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>
              <th v-else @click="sort_fun(true, 2)">
                直播销量
                <img src="@/assets/meng/up_down.png" v-if="orderBy == 'asc' && sort == 2" />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>

              <th @click="sort_fun(false, 3)" v-if="orderBy == 'desc' && sort == 3" class="cursor">
                直播销售额
                <img
                  src="@/assets/meng/down_up.png"
                  v-if="orderBy == 'desc' && sort == 3"
                  class="sort"
                />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>
              <th v-else @click="sort_fun(true, 3)">
                直播销售额
                <img src="@/assets/meng/up_down.png" v-if="orderBy == 'asc' && sort == 3" />
                <img src="@/assets/meng/no_down_up.png" v-else />
              </th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, i) in searchpro" :key="i + 'q'">
              <td>
                <div class="live_box">
                  <div>
                    <img :src="item.roomLogo" @click="go_to_page(item.roomId, item.status)" v-errorImg:live />
                    <div class="live_box_01" v-if="item.status == 1">
                      <p class="livingGif">
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                      </p>
                    </div>
                  </div>

                  <div class="live_box_right">
                    <div
                      class="title"
                      @click="go_to_page(item.roomId, item.status)"
                    >{{ item.roomTitle }}</div>
                    <div class="time">开播:{{ timestamp(item.beginUnix, "M-D h:m") }}</div>
                  </div>
                </div>
              </td>
              <td>
                <div>
                  <img :src="item.logo" @click="go_to_page01(item.authorId)" />
                  <div @click="go_to_page01(item.authorId)">{{ item.nickName }}</div>
                </div>
              </td>
              <!-- <td>1分23秒</td> -->
              <td v-if="item.maxPrice > item.livePrice">￥{{ item.livePrice + "-" + item.maxPrice }}</td>
              <td v-else>￥{{ item.livePrice }}</td>
              <td>{{ format_num(item.volume) }}</td>
              <td>{{ format_num(item.amount) }}</td>
            </tr>
          </tbody>
        </table>
        <!-- <p
        class="nothing"
        v-if="searchpro.length && !listLoading && page * size >= total"
      >
        我是有底线的～
        </p>-->
        <!-- <div class="zwbox" v-if="showroomList.length==0 && !listLoading"> -->
        <div class="zw_box" v-if="searchpro.length == 0 && !listLoading">
          <div class="zw" v-if="searchpro.length == 0 && !listLoading">
            <img src="@/assets/liu/zw.png" />
            <p>暂无数据</p>
          </div>
        </div>
        <!-- </div> -->

        <div class="pageBox" v-if="total > size && !listLoading && searchpro.length">
          <el-pagination
            background
            layout="prev, pager, next, jumper"
            :total="total"
            :page-size="size"
            :current-page="page"
            @current-change="get_data"
            :hide-on-single-page="true"
          ></el-pagination>
        </div>
      </template>
      <div
        class="liveDetails_box"
        v-if="searchpro.length == 0 && listLoading && !once"
        style="margin-top: 30px; margin-bottom: 100px"
        v-loading="listLoading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
      ></div>
      <div
        v-if="once"
        style="margin-top: 30px; margin-bottom: 100px"
        v-loading="listLoading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
      ></div>
    </template>
    <div class="dialogEg" v-else>
      <img :src="$global.staticUrl + 'image/egImg/goodsJurisdiction2.png'" alt />
      <payVip routerName="compare" :lowestVipNum="vipRootObj[8][135].ownerMinLevel" />
    </div>
  </div>
</template>

<script>
// import live_houseVue from '../../meng/live/live_house.vue';
import KChart from '../../wang/talent/tdetails/NewComponents/KChart.vue';
export default {
  data() {
    return {
      once: true,
      size: 9,
      listLoading: false,
      total: null,
      searchpro: [],
      page: 1,
      sort: 0,
      KindName: '30天',
      liveTime: [],
      startDate: '',
      endDate: '',
      keyWords: '',
      orderBy: 'desc', //1降序 0升序
      // 销量趋势图
      plLoading: false,
      trend: [],
      trendX: [],
      trendY: [],

      // 选择时间 不可选的日期
      pickeroptions: {
        disabledDate: time => {
          return (
            time.getTime() < Date.now() - 180 * 24 * 60 * 60 * 1000 || time.getTime() > Date.now()
          ); // 返回 所有时间 大于 当前时间
        }
      },
      vipRootObj: this.$store.state.userRoot //会员权限对象
    };
  },
  components: {
    KChart
  },
  props: ['id'],
  computed: {},
  created() {
    if (this.vipRootObj[8][135].owner) {
      this.getTime();
    }
    this.gettrend();
    // this.setTBBar();
  },
  mounted() {
    // window.addEventListener("scroll", this.initHeight);
    // window.addEventListener("resize", () => {
    //   //给浏览器窗口绑定变化大小事件
    //   this.setTBBar();
    // });
  },
  watch: {
    KindName: function (newVal, oldVal) {
      if (this.KindName != '') {
        this.searchpro = [];
        this.page = 1;
        this.KindName = newVal;
        this.getTime();
        this.gettrend();
      }
    },
    keyWords: function (newVal, oldVal) {
      if (newVal == '') {
        this.getTime();
      }
    }
  },
  methods: {
    // 大屏直播间
    go_to_page(id, status) {
      if (status == 1) {
        let router = this.$router.resolve({
          path: `/live/${id}`
        });
        window.open(router.href, '_blank');
      } else {
        let router = this.$router.resolve({
          path: `/talent_main/liveDetailsRoot/${id}/0`
        });
        window.open(router.href, '_blank');
      }
    },
    // 达人详情
    go_to_page01(id) {
      let router = this.$router.resolve({
        path: `/talent_main/tdetails/${id}/${0}`
      });
      window.open(router.href, '_blank');
    },
    onPick1() {
      //自定义时间
      this.KindName = '';
      this.page = 1;
      this.searchpro = [];
      this.getTime();
      this.gettrend();
    },
    //搜索
    Search() {
      this.searchpro = [];
      this.page = 1;
      this.getTime();
    },
    // 分页
    get_data(page) {
      this.searchpro = [];
      this.page = page;
      this.getTime();
    },

    getTime() {
      this.listLoading = true;
      switch (this.KindName) {
        case '近7天':
          this.endDate = this.timestamp(Date.now() / 1000, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 6, 'Y-M-D');
          break;

        case '30天':
          this.endDate = this.timestamp(Date.now() / 1000, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 29, 'Y-M-D');
          break;
        case '90天':
          this.endDate = this.timestamp(Date.now() / 1000, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 89, 'Y-M-D');
          break;
        default:
          this.startDate = this.liveTime[0];
          this.endDate = this.liveTime[1];
          break;
      }
      this.liveTime = [this.startDate, this.endDate];
      let that = this;
      this.$axios
        .post(
          '/api/live/searchpro',
          {
            proId: this.id,
            // proId: "3480244482744692868",
            startDate: this.startDate,
            endDate: this.endDate,
            key: this.trimStr(this.keyWords),
            sort: this.sort,
            order_by: this.orderBy,
            page: this.page,
            size: this.size
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel != null) {
                that.cancel();
              }
              that.cancel = c;
            })
          }
        )
        .then(res => {
          this.listLoading = false;
          switch (this.KindName) {
            case '近7天':
              this.endDate = this.timestamp(Date.now() / 1000, 'Y-M-D');
              this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 6, 'Y-M-D');
              break;

            case '30天':
              this.endDate = this.timestamp(Date.now() / 1000, 'Y-M-D');
              this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 29, 'Y-M-D');
              break;
            case '90天':
              this.endDate = this.timestamp(Date.now() / 1000, 'Y-M-D');
              this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 89, 'Y-M-D');
              break;
            default:
              this.startDate = this.liveTime[0];
              this.endDate = this.liveTime[1];
              break;
          }
          if (res.data.code == 0) {
            this.once = false;
            this.searchpro = res.data.data;
            this.total = res.data.count;
          } else if (res.data.code == 1003) {
            this.once = false;
          } else {
            this.once = false;
          }
        });
    },
    gettrend() {
      this.plLoading = true;
      this.$axios
        .get(
          `/api/product/prolivetrend?proid=${this.id}&startdate=${this.startDate}&enddate=${this.endDate}`
        )
        .then(res => {
          if (res.data.code == 0) {
            this.plLoading = false;
            this.trend = res.data.data;
            this.trendX = res.data.data.trend[0].map(element => {
              return this.timestamp(element, 'M-D');
            });
            this.trendY = res.data.data.trend[1];
          }
        });
    },
    // 排序
    sort_fun(parm01, parm02) {
      if (parm01) {
        this.orderBy = 'desc';
      } else {
        this.orderBy = 'asc';
      }
      this.sort = parm02;
      this.searchpro = [];
      this.getTime();
    }
  }
};
</script>

<style scoped lang="less">
#liveDetails {
  min-width: 807px;
  padding-left: 20px;
  padding-right: 20px;
  width: 100%;
  box-sizing: border-box;
  .title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0;
    color: #222;
    position: relative;
    text-indent: 9px;
  }
  .title::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
    width: 4px;
    height: 16px;
    background-color: #fd7f2c;
    border-radius: 2px;
  }
  .zw_box {
    position: relative;
    height: 400px;
  }
  .top {
    // width: 100%;
    display: flex;
    justify-content: flex-end;
  }
  .optionsBox {
    margin-left: 10px;
  }
  // 销量趋势图
  .volume {
    display: flex;
    margin-top: 16px;
    div {
      width: 354px;
      line-height: 50px;
      padding: 0 52px;
      background: #f5f5f5;
      border-radius: 5px;
      box-sizing: border-box;
      font-size: 18px;
      color: #888;
      margin-right: 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      span {
        color: #222;
        font-family: DINAlternate-Bold;
      }
    }
  }
  .trend {
    width: 100%;
    height: 290px;
    .no_data {
      width: 100%;
      height: 290px;
      text-align: center;
      font-size: 14px;
      color: #888;
      img {
        display: block;
        margin: 120px auto 0px auto;
      }
    }
  }
  // 搜索框
  .searchBox {
    width: 308px;
    height: 32px;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #e5e5e5;
    margin-top: 20px;
    overflow: hidden;
    .el-input__inner {
      flex: 1;
    }
    .imgBox:hover {
      background: url('../../../assets/wang/talentCompare/search.png') no-repeat 10px 7px, #fff;
      background-size: 15px 15px;
    }
    .imgBox {
      width: 40px;
      height: 30px;
      border-radius: 0px 4px 4px 0px;
      cursor: pointer;
      display: grid;
      place-items: center;
      background: url('../../../assets/wang/talentCompare/search-nohover.png') no-repeat 10px 7px,
        #fff;
      background-size: 15px 15px;
      img {
        width: 15px;
        height: 15px;
      }
    }
  }
  table {
    width: 100%;
    margin-top: 10px;
    text-align: center;
    box-sizing: border-box;
    thead {
      img {
        width: 5px;
        height: 10px;
        vertical-align: 0;
      }
      tr {
        width: 100%;
        height: 48px;
        background-color: #f5f9ff;
        border-radius: 4px;
        font-size: 14px;
        font-weight: 400;
        font-stretch: normal;
        letter-spacing: 0;
        color: #555;
        th:nth-child(1) {
          min-width: 244px;
          text-align: left;
          padding-left: 39px;
        }
        th:nth-child(2) {
          width: 18%;
          text-align: left;
        }

        th:nth-child(3),
        th:nth-child(4),
        th:nth-child(5),
        th:nth-child(6) {
          width: 10.8%;
          cursor: pointer;
        }
      }
    }

    tbody {
      tr {
        height: 78px;
        .live_box {
          min-width: 360px;
          padding-left: 39px;
          display: flex;
          overflow: hidden;
          text-overflow: ellipsis;
          > div {
            > img {
              cursor: pointer;
              width: 50px;
              height: 50px;
              border-radius: 6px;
              object-fit: cover;
            }
          }
          .live_box_right {
            display: flex;
            flex-direction: column;
            justify-content: center;
          }
          .title {
            &:hover {
              color: #ff924b !important;
            }
            cursor: pointer;
            text-align: left;
            font-size: 14px;
            font-weight: 600;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #222222;
            white-space: nowrap;
            max-width: 200px;

            overflow: hidden;
            text-overflow: ellipsis;
          }
          .time {
            font-size: 13px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #888888;
            text-align: left;
            margin-top: 7px;
            white-space: nowrap;
          }
          > div {
            position: relative;
            margin-right: 11px;
            .live_box_01 {
              position: absolute;
              bottom: 0px;
              right: -1px;
              width: 18px;
              height: 18px;

              background-image: linear-gradient(90deg, #ff295d 1%, #fa4fa2 100%),
                linear-gradient(#ffffff, #ffffff);
              background-blend-mode: normal, normal;
              border-radius: 6px 0 4px 0px;
              font-size: 12px;
              color: #ffffff;
              display: flex;
              align-items: center;
              justify-content: center;
              padding-left: 2px;
            }
          }
        }
        td:nth-child(2) {
          > div {
            display: flex;
            justify-content: flex-start;
            align-items: center;

            > img {
              width: 50px;
              height: 50px;
              border: 1px solid #e5e5e5;
              border-radius: 50%;
              margin-right: 10px;
              cursor: pointer;
            }
            > div {
              &:hover {
                color: #ff924b !important;
              }
              cursor: pointer;
              font-size: 14px;
              color: #222;
              font-weight: 600;
              white-space: nowrap;
            }
          }
        }

        td:nth-child(3),
        td:nth-child(4),
        td:nth-child(5),
        td:nth-child(6) {
          font-family: DINAlternate-Bold;
          font-size: 15px;
          color: #222;
          white-space: nowrap;
        }
      }
    }
  }
}
</style>
